import socket

'''
通过域名获取IP

'''


def main(url):
    if 'http://' in url:
        name = url.replace('http://', '')
    else:
        name = url.replace('https://', '')
    try:
        info = socket.getaddrinfo(name, 80, 0, 0, socket.SOL_TCP)
        print(info)
        print(info[0][4][0])
    except socket.gaierror as err:
        print(err)


if __name__ == '__main__':
    data = ['www.baidu.com']
    for link in data:
        print(link)
        main(link)